#!/usr/bin/env python
# -*- coding: utf-8 -*- 

#Kiwi Bot
#Copyright (C) 2009 Mathieu "MathX" Xhonneux
#Modified by @nge1nCorsic4 in 2010
#Modified by @nge1nCorsic4 in 2011
#Modified by @nge1nCorsic4 in 2012
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License along
#with this program; if not, write to the Free Software Foundation, Inc.,
#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import kiwi, kiwi.config, kiwi.lang
import os, time

class logging:
	def __init__(self):
		self.lang = kiwi.lang.Lang(self,'base')
		if os.name == 'nt':
			self.end = '\r\n'
		elif os.name == 'mac':
			self.end = '\r'
		else:
			self.end = '\n'
		config = kiwi.config.configuration()
		self.path = kiwi.getPath(config.kiwi.logfile)
		if not os.path.isfile(self.path):
			f = file(self.path,'w')
			f.close()
		if os.path.getsize(self.path) > 500000 :
			old = time.strftime('.%d-%m-%y',time.localtime())
			os.rename(self.path, self.path+old)
			f = file(self.path,'w')
			f.close()
		self.write('------------------------------------'+self.end)
		self.info(self.lang.lang('', '10012'))
	def write(self,msg):
		f = file(self.path,'a')
		msg = self.date() + ' | ' + msg + self.end
		f.write(msg)
		f.close()
	def info(self, msg):
		self.write('[INFO] ' + msg)
	def debug(self,msg):
		self.write('[DEBUG] ' + msg)
	def warn(self,msg):
		self.write('[WARNING] ' + msg)
	def error(self,msg):
		self.write('[ERROR] ' + msg)
	def ban(self,msg):
		self.write('[BAN] ' + msg)
	def kick(self,msg):
		self.write('[KICK] ' + msg)
	def date(self):
		return time.strftime('%d/%m/%y %H:%M', time.localtime())